#[cfg(test)]
mod tests {
    trait Animal {
        fn speak(&self) -> String;
    }

    struct Dog;
    struct Cat;

    impl Animal for Dog {
        fn speak(&self) -> String {
            "Woof!".to_string()
        }
    }

    impl Animal for Cat {
        fn speak(&self) -> String {
            "Meow!".to_string()
        }
    }

    /// 测试trait实现的基本机制
    /// 验证动态派发与静态派发的差异
    /// 演示Rust的多态性实现方式
    #[test]
    fn test_trait_impl() {
        let dog = Dog;
        let cat = Cat;
        assert_eq!(dog.speak(), "Woof!");
        assert_eq!(cat.speak(), "Meow!");
    }

    /// 测试泛型函数的类型约束
    /// 验证PartialOrd trait边界的使用
    /// 演示编译时多态的实现机制
    #[test]
    fn test_generic_function() {
        fn largest<T: PartialOrd>(list: &[T]) -> &T {
            let mut largest = &list[0];
            for item in list {
                if item > largest {
                    largest = item;
                }
            }
            largest
        }

        let numbers = vec![34, 50, 25, 100, 65];
        assert_eq!(*largest(&numbers), 100);
    }
}